%%% -*- mode: erlang -*-
-ifndef(rtps_hrl).
-define(rtps_hrl, true).

-include("../include/rtps.hrl").

%% 8.3.3.1.2 version
-define(VERSION, #protocol_version{major = ?VERSION_MAJOR, minor = ?VERSION_MINOR}).

%% 9.6.1.2 Given UDP port numbers, the number of Participants per
%% domain is normaly limitied to 120 because the number of ports is
%% limited for IPv4.
-define(MAX_DOMAINS, 233).
-define(MAX_PARTICIPANTS, 120).

%% Max number of entries in a number set. DO NOT CHANGE
-define(MAX_NS_SIZE, 256). 

%% Table 8.47 - RTPS Writer Attributes: Default heartbeat period in
%% ms. Just picked a number used in some other implementations.
-define(HEARTBEAT_PERIOD, 3000).
-define(NACK_RESPONSE_DELAY, 200).
-define(NACK_SUPPRESSION_DURATION, 0).

%% 8.4.10.1.1 RTPS Reader Default Timing-Related Values
-define(HEARTBEAT_RESPONSE_DELAY, 500).
-define(HEARTBEAT_SUPPRESSION_DURATION, 0).

%% 8.4.14.1.1 How to select the fragment size
-define(MIN_FRAGMENT_SIZE, 1024).
-define(MAX_FRAGMENT_SIZE, 16#ffff).

%% 9.6.1.4.2 Default announcement rate (SPDP)
-define(RESEND_PERIOD, 30000). % 30 seconds

%% Table 9.13 - ParameterId mapping and default values p187.
-define(PARTICIPANT_LEASE_DURATION, 100000). % 100 seconds 

%%==============================================================================
%% Internal data representation
%%==============================================================================

-record(entity_id, {type :: rtps:entity_type(),
		    kind :: rtps:entity_kind(),
		    key :: rtps:entity_key()}).

-record(guid, {guid_prefix :: rtps:guid_prefix(), 
	       entity_id :: rtps:entity_id()}).

-record(sequence_number_set, {base :: rtps:sequence_number(), 
			      set :: list(rtps:sequence_number()),
			      num_bits :: 1..256}).

-record(fragment_number_set, {base :: rtps:fragment_number(), 
			      set :: list(rtps:fragment_number()),
			      num_bits :: 1..256}).

-record(time, {seconds :: rtps:seconds(),
	       fraction :: rtps:fraction()}).

-record(locator, {kind :: rtps:locator_kind(),
		  port :: rtps:locator_port(),
		  address :: rtps:locator_address()}).

-record(locator_udpv4, {address :: inet:ip4_address(),
			port :: inet:port_number()}).

-record(protocol_version, {major :: rtps:major_protocol_version(),
			   minor :: rtps:minor_protocol_version()}).

-record(content_filter_property, {content_filtered_topic_name :: string(), 
				  related_topic_name :: string(),
				  filter_class_name :: string(), 
				  filter_expression :: string(), 
				  expression_parameters :: list(string())}).

-record(content_filter_info, {filter_result :: list(0..16#7fffffff), 
			      filter_signatures :: list({0..16#7fffffff, 0..16#7fffffff,
							 0..16#7fffffff, 0..16#7fffffff})}).

-record(property, {name :: string(),
		   value :: string()}).

-record(parameter, {id :: atom() | 2..16#7fff,
		    value :: term()}).

-record(original_writer_info, {original_writer_guid :: rtps:guid(),
			       original_writer_sn :: rtps:sequence_number(),
			       original_writer_qos :: [rtps:parameter()]}).

%% Messages related records.
-record(acknack, {final_flag, reader_id, writer_id, 
		  reader_sn_state :: rtps:sequence_number_set(), count}).
-record(data_msg, {endianness, extra_flags, reader_id, writer_id, writer_sn, 
		   inline_qos :: [rtps:parameter()] | undefined,
		   serialized_key :: binary() | undefined,
		   serialized_data :: binary() | undefined}).
-record(data_frag, {endianness, key_flag, extra_flags, reader_id, writer_id, writer_sn,
		    fragment_starting_num, fragments_in_submessage, fragment_size, sample_size, 
		    inline_qos :: [rtps:parameter()] | undefined, serialized_payload}).
-record(gap, {reader_id, writer_id, gap_start, gap_list}).
-record(heartbeat, {final_flag, liveliness_flag, reader_id, writer_id, first_sn, last_sn,
		    count}).
-record(heartbeat_frag, {reader_id, writer_id, writer_sn, last_fragment_num, count}).
-record(info_destination, {guid_prefix}).
-record(info_reply, {unicast_locator_list, multicast_locator_list}).
-record(info_reply_ip4, {unicast_locator, multicast_locator}).
-record(info_source, {protocol_version :: rtps:protocol_version(), vendor_id, guid_prefix}).
-record(info_timestamp, {timestamp}).
-record(nack_frag, {reader_id, writer_id, writer_sn, 
		    fragment_number_state :: rtps:fragment_number_set(), count}).
-record(pad, {}).

-record(msg, {src_guid :: rtps:guid(),
	      dst_guid :: rtps:guid(),
	      submsg :: rtps:submessage(),
	      reply_to :: [rtps:locator()] | undefined,
	      timestamp,
	      size :: pos_integer() | undefined}).


%% 9.6.2.1 Data Representation for the ParticipantMessageData Built-in Endpoints
-record(participant_message_data, {participant_guid_prefix :: rtps:guid_prefix(),
				   kind :: unknown | automatic_liveliness_update |
					   manual_liveliness_update,
				  data :: binary()}).

-endif.
